.text
.align 8
.section .rodata
.LC0:
    .string "numbers.dat"
.LC1:
    .string "wb"
.LC2:
    .string "Could not open %s for output.\n"
.LC3:
    .string "rb"
.LC4:
    .string "Could not open %s for random access.\n"
.LC5:
    .string "Enter an index in the range 0-%d.\n"
.LC6:
    .string "%d"
.LC7:
    .string "The value there is %f.\n"
.LC8:
    .string "Next index (out of range to quit):"
.LC9:
    .string "Bye!"
.align 8
.LC10:
    .long	0
	.long	1079574528
.align 8
.LC11:
    .long	0
	.long	1072693248

.text
.globl main
.type main, @function
main:
    pushq %rbp
    movq %rsp, %rbp

    subq $8032, %rsp
    // 分配局部变量
    // numbers: -8000(%rbp) /* numbers */
    // value: -8008(%rbp) /* value */
    // file: -8016(%rbp) /* file */
    // i: -8020(%rbp) /* i */
    // pos: -8024(%rbp) /* pos */
    // iofile: -8032(%rbp) /* iofile */
    leaq .LC0(%rip), %rax
    movq %rax, -8016(%rbp) /* file */

.FOR_14_INIT:
    movl $0, -8020(%rbp) /* i */
    jmp .FOR_14_COMPARE
.FOR_14_ENTER:
    movl -8020(%rbp) /* i */, %eax
    addl $1, %eax
    movl %eax, %edx
    pxor %xmm1, %xmm1
    cvtsi2sdl %eax, %xmm1
    movsd .LC10(%rip), %xmm0
    mulsd %xmm0, %xmm1

    pxor %xmm2, %xmm2
    cvtsi2sdl %eax, %xmm2
    movsd .LC11(%rip), %xmm0
    divsd %xmm2, %xmm0
    addsd %xmm1, %xmm0

    movl -8020(%rbp) /* i */, %eax
    cltq
    movsd %xmm0, -8000(%rbp, %rax, 8)
.FOR_14_INCR:
    incl -8020(%rbp) /* i */
.FOR_14_COMPARE:
    cmpl $1000, -8020(%rbp) /* i */
    jl .FOR_14_ENTER
.FOR_14_END:
    movq -8016(%rbp) /* file */, %rdi
    leaq .LC1(%rip), %rsi
    call fopen
    movq %rax, -8032(%rbp) /* iofile */
    cmpq $0, %rax
    jne .OPEN_IO_FILE_SUCCESS
.OPEN_IO_FILE_FAILED:
    leaq stderr(%rip), %rax
    movq (%rax), %rdi
    leaq .LC2(%rip), %rsi
    movq -8016(%rbp) /* file */, %rdx
    call fprintf
    movl $1, %eax
    call exit
.OPEN_IO_FILE_SUCCESS:
    leaq -8000(%rbp) /* numbers */, %rdi
    movq $8, %rsi
    movq $1000, %rdx
    movq -8032(%rbp) /* iofile */, %rcx
    call fwrite

    movq -8032(%rbp) /* iofile */, %rdi
    call fclose

    movq -8016(%rbp) /* file */, %rdi
    leaq .LC3(%rip), %rsi
    call fopen
    movq %rax, -8032(%rbp) /* iofile */
    cmpq $0, %rax
    jne .OPEN_RD_IO_FILE_SUCCESS
.OPEN_RD_IO_FILE_FAILED:
    leaq stderr(%rip), %rax
    movq (%rax), %rdi
    leaq .LC4(%rip), %rsi
    movq -8016(%rbp) /* file */, %rdx
    call fprintf
    movl $1, %eax
    call exit
.OPEN_RD_IO_FILE_SUCCESS:
    leaq .LC5(%rip), %rdi
    movl $1000, %esi
    call printf

    jmp .WHILE_33_COMPARE
.WHILE_33_ENTER:
    movl -8020(%rbp) /* i */, %eax
    sall $3, %eax
    movl %eax, -8024(%rbp) /* pos */
    movq -8032(%rbp) /* iofile */, %rdi
    movl -8024(%rbp) /* pos */, %esi
    movl $0, %edx
    call fseek
    leaq -8008(%rbp) /* value */, %rdi
    movq $8, %rsi
    movl $1, %edx
    movq -8032(%rbp) /* iofile */, %rcx
    call fread
    leaq .LC7(%rip), %rdi
    movq -8008(%rbp) /* value */, %xmm0
    movl $1, %eax
    call printf
    leaq .LC8(%rip), %rdi
    call puts
.WHILE_33_INCR:
    // nothing to do
.WHILE_33_COMPARE:
    leaq .LC6(%rip), %rdi
    leaq -8020(%rbp) /* i */, %rsi
    call scanf
    cmpl $1, %eax
    jne .WHILE_33_END
    cmpl $0, -8020(%rbp) /* i */
    jl .WHILE_33_END
    cmpl $1000, -8020(%rbp) /* i */
    jge .WHILE_33_END
    jmp .WHILE_33_ENTER
.WHILE_33_END:
    movq -8032(%rbp) /* iofile */, %rdi
    call fclose

    leaq .LC9(%rip), %rdi
    call puts

    movl $0, %eax
    leave
    ret